package com.killer.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.killer.util.Globals;


/**
 * Created by killer on 2016/4/21.
 */
public class MyView extends View {
    private String content = "盖闻天地之数，有十二万九千六百岁为一元。将一元分为十二会，乃子、丑、寅、卯、辰、巳、午、未、申、酉、" +
            "戌、亥之十二支也。每会该一万八百岁。且就一日而论：子时得阳气，而丑则鸡鸣；寅不通光，而卯则日出；辰时食后，而巳则挨排" +
            "；日午天中，而未则西蹉；申时晡而日落酉；戌黄昏而人定亥。譬于大数，若到戌会之终，则天地昏蒙而万物否矣。再去五千四百岁" +
            "，交亥会之初，则当黑暗，而两间人物俱无矣，故曰混沌。又五千四百岁，亥会将终，贞下起元，近子之会，而复逐渐开明。邵康节曰" +
            "：“冬至子之半，天心无改移。一阳初动处，万物未生时。”到此，天始有根。再五千四百岁，正当子会，轻清上腾" +
            "，有日，有月，有星，有辰。日、月、星、辰，谓之四象。故曰，天开于子。又经五千四百岁，子会将终，近丑之会，而逐渐坚实。";

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setTextSize(Globals.CHAR_SIZE);

        for (int i = 0;i<Globals.LINE_COUNT;i++){
            for (int j = 0;j<Globals.LINE_CHAR_COUNT;j++){
                if (j+i*Globals.LINE_CHAR_COUNT<content.length()){
                    canvas.drawText(String.valueOf(content.charAt(j+i*Globals.LINE_CHAR_COUNT)),
                            Globals.PAGE_SEP+j*(Globals.CHAR_SIZE+Globals.CHAR_SEP),
                            (i+1)*(Globals.LINE_SEP+Globals.CHAR_SIZE),
                            paint);
                }
            }
        }
    }
}
